<?php
/**
 * Created by PhpStorm.
 * User: zhangxiang
 * Date: 2018/10/19
 * Time: 下午1:16
 */

namespace app\index\controller;


use app\model\FriendshipLink;
use think\App;
use think\Controller;
use think\facade\View;

class Base extends Controller
{
    protected $tpl;
    protected $prefix;
    protected $redis_prefix;
    protected $uid;
    protected $site_name;
    protected $img_site;

    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $vip_expire_time = session('vip_expire_time');
        if (!empty($vip_expire_time)){
            if($vip_expire_time - time() <= 0){ //计算出会员是否过期
                session('xwx_vip_expire_time', null);
            }
        }
    }

    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $this->uid = session('xwx_user_id');
        $this->prefix = config('database.prefix');
        $this->redis_prefix = config('cache.prefix');
        $tpl_root = './template/'.config('site.tpl').'/index/';
        $controller = strtolower($this->request->controller());
        $action = strtolower($this->request->action());
        if ($this->request->isMobile()){
            $this->tpl = $tpl_root.$controller.'/'.$action.'.html';
        }else{
            $this->tpl = $tpl_root.$controller.'/'.'pc_'.$action.'.html';
        }
        $links = cache('friendshipLink');
        if ($links == false){
            $links = FriendshipLink::all();
            cache('friendshipLink',$links,null,'redis');
        }
        $this->site_name = config('site.site_name');
        $this->img_site = config('site.img_site');
        View::share([
            'url' => config('site.url'),
            'site_name' => config('site.site_name'),
            'img_site' => config('site.img_site'),
            'links' => $links,
            'book_ctrl' => BOOKCTRL,
            'chapter_ctrl' => CHAPTERCTRL,
            'tag_ctrl' => TAGCTRL,
            'booklist_act' => BOOKLISTACT,
            'search_ctrl' => SEARCHCTRL,
            'rank_ctrl' => RANKCTRL,
            'update_act' => UPDATEACT,
            'author_ctrl' => AUTHORCTRL
        ]);
    }
}